package com.example.commons.config;

import com.alibaba.fastjson.JSONObject;
import com.example.commons.response.ResultCode;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 验证token失败时触发
 */
public class JwtAuthenticationEntryPoint implements AuthenticationEntryPoint {
    @Override
    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException {
        JSONObject resp = new JSONObject();
        resp.put("code", ResultCode.LOGOUT);
        resp.put("msg", "登录失效");
        resp.put("data", null);
        PrintWriterResult.result(response, resp);
    }
}
